package com.yuyu.storage.remote.fallback;


import com.yuyu.commons.interceptor.response.ResponseJson;
import com.yuyu.storage.remote.IStorageRepositoryMicroService;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author
 * @description: 库存远程调用
 * @date: 2022/12/9 9:22
 */
@Component
@Slf4j
public class IStorageMicroServiceFallbackFactory implements FallbackFactory<IStorageRepositoryMicroService> {
    @Override
    public IStorageRepositoryMicroService create(Throwable throwable) {
        log.error("GoodsRepository remote api is error,the reason is{}",throwable.toString());
        return  new IStorageRepositoryMicroService() {
            @Override
            public ResponseJson<Long> getStock(Long goodsId) {
                return ResponseJson.error("0","系统繁忙,请稍候再试!");
            }

            @Override
            public ResponseJson<Boolean> decStock(Long goodsId, Long stockNum) {
                return ResponseJson.error("rpc调用失败请稍候再试!");
            }

            @Override
            public ResponseJson<Boolean> rollBackStock(Long goodsId, Long stockNum) {
                return ResponseJson.error("rpc调用失败请稍候再试!");
            }
        };
    }
}
